Skip to content

Commit 11242c4

Browse files
committed
Add test for successfully creating a new custom attestation type
1 parent a9d16b4 commit 11242c4

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

cmd/kosli/createAttestationType.go

+28-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type createAttestationTypeOptions struct {
2020
}
2121

2222
type CreateAttestationTypePayload struct {
23-
TypeName string
23+
TypeName string `json:"type_name"`
2424
}
2525

2626
func newCreateAttestationTypeCmd(out io.Writer) *cobra.Command {
@@ -53,16 +53,41 @@ func (o *createAttestationTypeOptions) run(args []string) error {
5353
o.payload.TypeName = args[0]
5454
url := fmt.Sprintf("%s/api/v2/custom-attestation-types/%s", global.Host, global.Org)
5555

56+
form, err := prepareAttestationTypeForm(o.payload)
57+
if err != nil {
58+
return err
59+
}
60+
5661
reqParams := &requests.RequestParams{
5762
Method: http.MethodPost,
5863
URL: url,
59-
Payload: o.payload,
64+
Form: form,
6065
DryRun: global.DryRun,
6166
Token: global.ApiToken,
6267
}
63-
_, err := kosliClient.Do(reqParams)
68+
_, err = kosliClient.Do(reqParams)
6469
if err == nil && !global.DryRun {
6570
logger.Info("foo bar fix me %s", o.payload.TypeName)
6671
}
6772
return err
6873
}
74+
75+
func prepareAttestationTypeForm(payload interface{}) ([]requests.FormItem, error) {
76+
form, err := newAttestationTypeForm(payload)
77+
if err != nil {
78+
return []requests.FormItem{}, err
79+
}
80+
return form, nil
81+
}
82+
83+
// newAttestationTypeForm constructs a list of FormItems for an attestation-type
84+
// form submission.
85+
func newAttestationTypeForm(payload interface{}) (
86+
[]requests.FormItem, error,
87+
) {
88+
form := []requests.FormItem{
89+
{Type: "field", FieldName: "data_json", Content: payload},
90+
}
91+
92+
return form, nil
93+
}

cmd/kosli/createAttestationType_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,15 @@ func (suite *CreateAttestationTypeTestSuite) TestCustomAttestationTypeCmd() {
3232
cmd: "create attestation-type" + suite.defaultKosliArguments,
3333
golden: "Error: accepts 1 arg(s), received 0\n",
3434
},
35+
{
36+
name: "type name is provided",
37+
cmd: "create attestation-type wibble" + suite.defaultKosliArguments,
38+
golden: "attestation-type wibble was created\n",
39+
},
3540
}
3641

3742
runTestCmd(suite.T(), tests)
38-
}u
43+
}
3944

4045
// In order for 'go test' to run this suite, we need to create
4146
// a normal test function and pass our suite to suite.Run

0 commit comments

Comments
 (0)