|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | + "fmt" |
| 5 | + "testing" |
| 6 | + |
| 7 | + "github.com/stretchr/testify/suite" |
| 8 | +) |
| 9 | + |
| 10 | +// Define the suite, and absorb the built-in basic suite |
| 11 | +// functionality from testify - including a T() method which |
| 12 | +// returns the current testing context |
| 13 | +type ListAttestationTypesCommandTestSuite struct { |
| 14 | + suite.Suite |
| 15 | + defaultKosliArguments string |
| 16 | + acmeOrgKosliArguments string |
| 17 | + attestationName1 string |
| 18 | + attestationName2 string |
| 19 | +} |
| 20 | + |
| 21 | +func (suite *ListAttestationTypesCommandTestSuite) SetupTest() { |
| 22 | + suite.attestationName1 = "custom-attestation-type-1" |
| 23 | + suite.attestationName2 = "custom-attestation-type-2" |
| 24 | + global = &GlobalOpts{ |
| 25 | + ApiToken: "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6ImNkNzg4OTg5In0.e8i_lA_QrEhFncb05Xw6E_tkCHU9QfcY4OLTVUCHffY", |
| 26 | + Org: "docs-cmd-test-user", |
| 27 | + Host: "http://localhost:8001", |
| 28 | + } |
| 29 | + suite.defaultKosliArguments = fmt.Sprintf(" --host %s --org %s --api-token %s", global.Host, global.Org, global.ApiToken) |
| 30 | + CreateCustomAttestationType(suite.attestationName1, "testdata/person-schema.json", []string{".age > 21"}, suite.T()) |
| 31 | + CreateCustomAttestationType(suite.attestationName2, "testdata/person-schema.json", []string{".age < 25"}, suite.T()) |
| 32 | + CreateCustomAttestationType(suite.attestationName1, "testdata/person-schema.json", []string{".age > 21", ".age < 85"}, suite.T()) //Make a second version |
| 33 | + |
| 34 | + global.Org = "acme-org" |
| 35 | + global.ApiToken = "v3OWZiYWu9G2IMQStYg9BcPQUQ88lJNNnTJTNq8jfvmkR1C5wVpHSs7F00JcB5i6OGeUzrKt3CwRq7ndcN4TTfMeo8ASVJ5NdHpZT7DkfRfiFvm8s7GbsIHh2PtiQJYs2UoN13T8DblV5C4oKb6-yWH73h67OhotPlKfVKazR-c" |
| 36 | + suite.acmeOrgKosliArguments = fmt.Sprintf(" --host %s --org %s --api-token %s", global.Host, global.Org, global.ApiToken) |
| 37 | + |
| 38 | +} |
| 39 | + |
| 40 | +func (suite *ListAttestationTypesCommandTestSuite) TestListFlowsCmd() { |
| 41 | + tests := []cmdTestCase{ |
| 42 | + { |
| 43 | + name: "listing custom attestation types works when some exist", |
| 44 | + cmd: fmt.Sprintf(`list attestation-types %s`, suite.defaultKosliArguments), |
| 45 | + golden: "", |
| 46 | + }, |
| 47 | + { |
| 48 | + name: "listing custom attestation types works when there are none", |
| 49 | + cmd: fmt.Sprintf(`list attestation-types %s`, suite.acmeOrgKosliArguments), |
| 50 | + golden: "No attestation types were found.\n", |
| 51 | + }, |
| 52 | + { |
| 53 | + name: "listing custom attestation types with --output json works when some exist", |
| 54 | + cmd: fmt.Sprintf(`list attestation-types --output json %s`, suite.defaultKosliArguments), |
| 55 | + golden: "", |
| 56 | + }, |
| 57 | + { |
| 58 | + name: "listing custom attestation types with --output json works when there are none", |
| 59 | + cmd: fmt.Sprintf(`list attestation-types --output json %s`, suite.acmeOrgKosliArguments), |
| 60 | + golden: "[]\n", |
| 61 | + }, |
| 62 | + { |
| 63 | + wantError: true, |
| 64 | + name: "providing an argument causes an error", |
| 65 | + cmd: fmt.Sprintf(`list attestation-types xxx %s`, suite.defaultKosliArguments), |
| 66 | + golden: "Error: unknown command \"xxx\" for \"kosli list attestation-types\"\n", |
| 67 | + }, |
| 68 | + } |
| 69 | + |
| 70 | + runTestCmd(suite.T(), tests) |
| 71 | +} |
| 72 | + |
| 73 | +// In order for 'go test' to run this suite, we need to create |
| 74 | +// a normal test function and pass our suite to suite.Run |
| 75 | +func TestListAttestationTypesCommandTestSuite(t *testing.T) { |
| 76 | + suite.Run(t, new(ListAttestationTypesCommandTestSuite)) |
| 77 | +} |
0 commit comments