Skip to content

Commit

Permalink
add tests to fulcio.NewClient
Browse files Browse the repository at this point in the history
Signed-off-by: Jake Sanders <[email protected]>
  • Loading branch information
Jake Sanders committed Dec 4, 2021
1 parent 8439a2c commit 24a0aca
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions cmd/cosign/cli/fulcio/fulcio_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ import (
"crypto/rand"
"encoding/pem"
"errors"
"net/http"
"net/http/httptest"
"testing"

"github.com/go-openapi/runtime"

"github.com/sigstore/cosign/cmd/cosign/cli/options"
"github.com/sigstore/fulcio/pkg/generated/client/operations"
"github.com/sigstore/sigstore/pkg/oauthflow"
)
Expand Down Expand Up @@ -138,3 +141,33 @@ func TestGetCertForOauthID(t *testing.T) {
})
}
}

func TestNewClient(t *testing.T) {
t.Parallel()
expectedUserAgent := options.UserAgent()
requestReceived := false
testServer := httptest.NewServer(http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) {
requestReceived = true
file := []byte{}

got := r.UserAgent()
if got != expectedUserAgent {
t.Errorf("wanted User-Agent %q, got %q", expectedUserAgent, got)
}
w.WriteHeader(http.StatusOK)
_, _ = w.Write(file)
}))
defer testServer.Close()

client, err := NewClient(testServer.URL)
if err != nil {
t.Error(err)
}

_, _ = client.Operations.SigningCert(nil, nil)

if !requestReceived {
t.Fatal("no requests were received")
}
}

0 comments on commit 24a0aca

Please sign in to comment.