@@ -33,11 +33,11 @@ func dataSourceLoadTest() *common.DataSource {
33
33
34
34
// loadTestDataSourceModel maps the data source schema data.
35
35
type loadTestDataSourceModel struct {
36
- ID types.Int32 `tfsdk:"id"`
37
- ProjectID types.Int32 `tfsdk:"project_id"`
36
+ ID types.String `tfsdk:"id"`
37
+ ProjectID types.String `tfsdk:"project_id"`
38
38
Name types.String `tfsdk:"name"`
39
39
Script types.String `tfsdk:"script"`
40
- BaselineTestRunID types.Int32 `tfsdk:"baseline_test_run_id"`
40
+ BaselineTestRunID types.String `tfsdk:"baseline_test_run_id"`
41
41
Created types.String `tfsdk:"created"`
42
42
Updated types.String `tfsdk:"updated"`
43
43
}
@@ -57,11 +57,11 @@ func (d *loadTestDataSource) Schema(_ context.Context, _ datasource.SchemaReques
57
57
resp .Schema = schema.Schema {
58
58
Description : "Retrieves a k6 load test." ,
59
59
Attributes : map [string ]schema.Attribute {
60
- "id" : schema.Int32Attribute {
60
+ "id" : schema.StringAttribute {
61
61
Description : "Numeric identifier of the load test." ,
62
62
Required : true ,
63
63
},
64
- "project_id" : schema.Int32Attribute {
64
+ "project_id" : schema.StringAttribute {
65
65
Description : "The identifier of the project this load test belongs to." ,
66
66
Computed : true ,
67
67
},
@@ -73,7 +73,7 @@ func (d *loadTestDataSource) Schema(_ context.Context, _ datasource.SchemaReques
73
73
Description : "The k6 test script content." ,
74
74
Computed : true ,
75
75
},
76
- "baseline_test_run_id" : schema.Int32Attribute {
76
+ "baseline_test_run_id" : schema.StringAttribute {
77
77
Description : "Identifier of a baseline test run used for results comparison." ,
78
78
Computed : true ,
79
79
},
@@ -98,35 +98,45 @@ func (d *loadTestDataSource) Read(ctx context.Context, req datasource.ReadReques
98
98
return
99
99
}
100
100
101
+ intID , err := strconv .ParseInt (state .ID .ValueString (), 10 , 32 )
102
+ if err != nil {
103
+ resp .Diagnostics .AddError (
104
+ "Error parsing load test ID" ,
105
+ "Could not parse load test ID '" + state .ID .ValueString ()+ "': " + err .Error (),
106
+ )
107
+ return
108
+ }
109
+ loadTestID := int32 (intID )
110
+
101
111
// Retrieve the load test attributes
102
112
ctx = context .WithValue (ctx , k6 .ContextAccessToken , d .config .Token )
103
- k6Req := d .client .LoadTestsAPI .LoadTestsRetrieve (ctx , state . ID . ValueInt32 () ).
113
+ k6Req := d .client .LoadTestsAPI .LoadTestsRetrieve (ctx , loadTestID ).
104
114
XStackId (d .config .StackID )
105
115
106
116
lt , _ , err := k6Req .Execute ()
107
117
if err != nil {
108
118
resp .Diagnostics .AddError (
109
119
"Error reading k6 load test" ,
110
- "Could not read k6 load test with id " + strconv . Itoa ( int ( state .ID .ValueInt32 ()) )+ ": " + err .Error (),
120
+ "Could not read k6 load test with id " + state .ID .ValueString ( )+ ": " + err .Error (),
111
121
)
112
122
return
113
123
}
114
124
115
125
// Retrieve the load test script content
116
- scriptReq := d .client .LoadTestsAPI .LoadTestsScriptRetrieve (ctx , state . ID . ValueInt32 () ).
126
+ scriptReq := d .client .LoadTestsAPI .LoadTestsScriptRetrieve (ctx , loadTestID ).
117
127
XStackId (d .config .StackID )
118
128
119
129
script , _ , err := scriptReq .Execute ()
120
130
if err != nil {
121
131
resp .Diagnostics .AddError (
122
132
"Error reading k6 load test script" ,
123
- "Could not read k6 load test script with id " + strconv . Itoa ( int ( state .ID .ValueInt32 ()) )+ ": " + err .Error (),
133
+ "Could not read k6 load test script with id " + state .ID .ValueString ( )+ ": " + err .Error (),
124
134
)
125
135
return
126
136
}
127
137
128
138
state .Name = types .StringValue (lt .GetName ())
129
- state .ProjectID = types .Int32Value ( lt .GetProjectId ())
139
+ state .ProjectID = types .StringValue ( strconv . Itoa ( int ( lt .GetProjectId ()) ))
130
140
state .BaselineTestRunID = handleBaselineTestRunID (lt .GetBaselineTestRunId ())
131
141
state .Script = types .StringValue (script )
132
142
state .Created = types .StringValue (lt .GetCreated ().Format (time .RFC3339Nano ))
@@ -136,10 +146,10 @@ func (d *loadTestDataSource) Read(ctx context.Context, req datasource.ReadReques
136
146
resp .Diagnostics .Append (diags ... )
137
147
}
138
148
139
- func handleBaselineTestRunID (baselineTestRunID int32 ) types.Int32 {
149
+ func handleBaselineTestRunID (baselineTestRunID int32 ) types.String {
140
150
if baselineTestRunID == 0 {
141
151
// If the API returned 0, set it as null
142
- return types .Int32Null ()
152
+ return types .StringNull ()
143
153
}
144
- return types .Int32Value ( baselineTestRunID )
154
+ return types .StringValue ( strconv . Itoa ( int ( baselineTestRunID )) )
145
155
}
0 commit comments