-
Notifications
You must be signed in to change notification settings - Fork 11
/
feature_commands.go
175 lines (139 loc) · 5.54 KB
/
feature_commands.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// Copyright 2023 VMware, Inc. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
// Package featureflags provides api command helpers and validators to write compatibility tests for feature apis
package featureflags
import (
"fmt"
"strconv"
"github.com/vmware-tanzu/tanzu-plugin-runtime/test/compatibility/core"
)
// NewSetFeatureCommand constructs a command to make a call to specific runtime version SetFeature API
// Input Parameter inputOpts has all input parameters which are required for Runtime SetFeature API
// Input Parameter: outputOpts has details about expected output from Runtime SetFeature API call
// Return: command to execute or error if any validations fails for SetFeatureInputOptions or SetFeatureOutputOptions
// This method does validate the input parameters SetFeatureInputOptions or SetFeatureOutputOptions based on Runtime API Version
// For more details about supported parameters refer to SetFeatureInputOptions or SetFeatureOutputOptions definition(and FeatureOpts struct, which is embedded)
func NewSetFeatureCommand(inputOpts *SetFeatureInputOptions, outputOpts *SetFeatureOutputOptions) (*core.Command, error) {
// Init the Command object
c := &core.Command{}
// Init the API object
api := &core.API{}
// Set API name
api.Name = core.SetFeatureAPI
// Validate the SetFeature input arguments
_, err := inputOpts.Validate()
if err != nil {
return nil, err
}
// Set API version
api.Version = inputOpts.RuntimeVersion
// Construct the SetFeature API arguments
api.Arguments = map[core.APIArgumentType]interface{}{
core.Plugin: inputOpts.Plugin,
core.Key: inputOpts.Key,
core.Value: inputOpts.Value,
}
// Construct Output parameters
var res = core.Success
var content = ""
if outputOpts != nil && outputOpts.Error != "" {
res = core.Failed
content = outputOpts.Error
}
api.Output = &core.Output{
Result: res,
Content: content,
}
c.APIs = append(c.APIs, api)
return c, nil
}
// NewIsFeatureEnabledCommand constructs a command to make a call to specific runtime version IsFeatureEnabled API
// Input Parameter inputOpts has all input parameters which are required for Runtime IsFeatureEnabled API
// Input Parameter: outputOpts has details about expected output from Runtime IsFeatureEnabled API call
// Return: command to execute or error if any validations fails for IsFeatureEnabledInputOptions or IsFeatureEnabledOutputOptions
// This method does validate the input parameters IsFeatureEnabledInputOptions or IsFeatureEnabledOutputOptions based on Runtime API Version
// For more details about supported parameters refer to IsFeatureEnabledInputOptions or IsFeatureEnabledOutputOptions definition(and FeatureOpts struct, which is embedded)
func NewIsFeatureEnabledCommand(inputOpts *IsFeatureEnabledInputOptions, outputOpts *IsFeatureEnabledOutputOptions) (*core.Command, error) {
// Init the Command object
c := &core.Command{}
// Init the API object
api := &core.API{}
// Set API name
api.Name = core.IsFeatureEnabledAPI
// Validate the Input Options
_, err := inputOpts.Validate()
if err != nil {
return nil, err
}
// Set API version
api.Version = inputOpts.RuntimeVersion
// Construct the IsFeatureEnabled API arguments
api.Arguments = map[core.APIArgumentType]interface{}{
core.Plugin: inputOpts.Plugin,
core.Key: inputOpts.Key,
core.Feature: fmt.Sprintf("features.%v.%v", inputOpts.Plugin, inputOpts.Key),
}
// Construct Output parameters
var res core.Result
var content string
if outputOpts.Error != "" {
res = core.Failed
content = outputOpts.Error
} else {
// Validate the Output Options
_, err = outputOpts.Validate()
if err != nil {
return nil, err
}
content = strconv.FormatBool(outputOpts.FeatureEnabled)
res = core.Success
}
api.Output = &core.Output{
Result: res,
Content: content,
}
if outputOpts.ValidationStrategy != "" {
api.Output.ValidationStrategy = outputOpts.ValidationStrategy
}
c.APIs = append(c.APIs, api)
return c, nil
}
// NewDeleteFeatureCommand constructs a command to make a call to specific runtime version DeleteFeature API
// Input Parameter inputOpts has all input parameters which are required for Runtime DeleteFeature API
// Input Parameter: outputOpts has details about expected output from Runtime DeleteFeature API call
// Return: command to execute or error if any validations fails for DeleteFeatureInputOptions or DeleteFeatureOutputOptions
// This method does validate the input parameters DeleteFeatureInputOptions or DeleteFeatureOutputOptions based on Runtime API Version
// For more details about supported parameters refer to DeleteFeatureInputOptions or DeleteFeatureOutputOptions definition(and FeatureOpts struct, which is embedded)
func NewDeleteFeatureCommand(inputOpts *DeleteFeatureInputOptions, outputOpts *DeleteFeatureOutputOptions) (*core.Command, error) {
// Init the Command object
c := &core.Command{}
// Init the API object
api := &core.API{}
// Set API name
api.Name = core.DeleteFeatureAPI
// Validate the input options
_, err := inputOpts.Validate()
if err != nil {
return nil, err
}
// Set API version
api.Version = inputOpts.RuntimeVersion
// Construct the context api arguments and output
api.Arguments = map[core.APIArgumentType]interface{}{
core.Plugin: inputOpts.Plugin,
core.Key: inputOpts.Key,
}
// Construct Output parameters
var res = core.Success
var content = ""
if outputOpts != nil && outputOpts.Error != "" {
res = core.Failed
content = outputOpts.Error
}
api.Output = &core.Output{
Result: res,
Content: content,
}
c.APIs = append(c.APIs, api)
return c, nil
}