|
4 | 4 | "crypto/hmac" |
5 | 5 | "crypto/sha256" |
6 | 6 | "encoding/hex" |
| 7 | + "encoding/json" |
7 | 8 | "fmt" |
| 9 | + "io" |
8 | 10 | "net/http" |
9 | 11 | "strings" |
10 | 12 | "testing" |
@@ -752,6 +754,36 @@ func TestVerifyRepoAndUser(t *testing.T) { |
752 | 754 | wantRepoNil: false, |
753 | 755 | wantErr: false, |
754 | 756 | }, |
| 757 | + { |
| 758 | + name: "happy path with ok-to-test comment status reporting", |
| 759 | + runevent: info.Event{ |
| 760 | + Organization: "owner", |
| 761 | + Repository: "repo", |
| 762 | + URL: "https://example.com/owner/repo", |
| 763 | + SHA: "123abc", |
| 764 | + EventType: opscomments.OkToTestCommentEventType.String(), |
| 765 | + TriggerTarget: triggertype.PullRequest, |
| 766 | + Sender: "owner", |
| 767 | + Request: request, |
| 768 | + }, |
| 769 | + repositories: []*v1alpha1.Repository{{ |
| 770 | + ObjectMeta: metav1.ObjectMeta{Name: "repo", Namespace: "ns"}, |
| 771 | + Spec: v1alpha1.RepositorySpec{ |
| 772 | + URL: "https://example.com/owner/repo", |
| 773 | + GitProvider: &v1alpha1.GitProvider{ |
| 774 | + Secret: &v1alpha1.Secret{ |
| 775 | + Name: "secret", |
| 776 | + }, |
| 777 | + WebhookSecret: &v1alpha1.Secret{ |
| 778 | + Name: "webhook-secret", |
| 779 | + }, |
| 780 | + }, |
| 781 | + }, |
| 782 | + }}, |
| 783 | + webhookSecret: "secret", |
| 784 | + wantRepoNil: false, |
| 785 | + wantErr: false, |
| 786 | + }, |
755 | 787 | } |
756 | 788 |
|
757 | 789 | pacInfo := &info.PacOpts{Settings: settings.DefaultSettings()} |
@@ -786,14 +818,23 @@ func TestVerifyRepoAndUser(t *testing.T) { |
786 | 818 | // status endpoint stub (used when CreateStatus is called) |
787 | 819 | mux.HandleFunc( |
788 | 820 | fmt.Sprintf("/repos/%s/%s/statuses/%s", tt.runevent.Organization, tt.runevent.Repository, tt.runevent.SHA), |
789 | | - func(rw http.ResponseWriter, _ *http.Request) { fmt.Fprint(rw, `{}`) }, |
| 821 | + func(rw http.ResponseWriter, r *http.Request) { |
| 822 | + body, _ := io.ReadAll(r.Body) |
| 823 | + a := struct { |
| 824 | + State string `json:"state"` |
| 825 | + }{} |
| 826 | + err := json.Unmarshal(body, &a) |
| 827 | + assert.NilError(t, err) |
| 828 | + assert.Equal(t, a.State, "success") |
| 829 | + fmt.Fprint(rw, `{}`) |
| 830 | + }, |
790 | 831 | ) |
791 | 832 |
|
792 | 833 | vcx := &ghprovider.Provider{Token: github.Ptr("token"), Logger: logger} |
793 | 834 | vcx.SetGithubClient(ghClient) |
794 | 835 | vcx.SetPacInfo(pacInfo) |
795 | 836 |
|
796 | | - k8int := &kitesthelper.KinterfaceTest{GetSecretResult: map[string]string{"pipelines-as-code-secret": tt.webhookSecret}} |
| 837 | + k8int := &kitesthelper.KinterfaceTest{GetSecretResult: map[string]string{"pipelines-as-code-secret": tt.webhookSecret, "secret": "token", "webhook-secret": "secret"}} |
797 | 838 |
|
798 | 839 | stdata, _ := testclient.SeedTestData(t, ctx, testclient.Data{Repositories: tt.repositories /*Secret: []*corev1.Secret{secret}*/}) |
799 | 840 | in := info.NewInfo() |
|
0 commit comments