Skip to content

Commit

Permalink
Revert "Make min and max instances a nested property of scaling confi…
Browse files Browse the repository at this point in the history
…guration"

This reverts commit d7aaa94.
  • Loading branch information
mattt committed Jun 10, 2024
1 parent d7aaa94 commit cfb9bda
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 64 deletions.
96 changes: 39 additions & 57 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1765,11 +1765,9 @@ func TestGetDeployment(t *testing.T) {
Name: "Acme, Inc.",
},
Configuration: replicate.DeploymentConfiguration{
Hardware: "gpu-t4",
Scaling: replicate.DeploymentScalingConfiguration{
MinInstances: 1,
MaxInstances: 5,
},
Hardware: "gpu-t4",
MinInstances: 1,
MaxInstances: 5,
},
},
}
Expand Down Expand Up @@ -1810,8 +1808,8 @@ func TestGetDeployment(t *testing.T) {
assert.Equal(t, "acme", deployment.CurrentRelease.CreatedBy.Username)
assert.Equal(t, "Acme, Inc.", deployment.CurrentRelease.CreatedBy.Name)
assert.Equal(t, "gpu-t4", deployment.CurrentRelease.Configuration.Hardware)
assert.Equal(t, 1, deployment.CurrentRelease.Configuration.Scaling.MinInstances)
assert.Equal(t, 5, deployment.CurrentRelease.Configuration.Scaling.MaxInstances)
assert.Equal(t, 1, deployment.CurrentRelease.Configuration.MinInstances)
assert.Equal(t, 5, deployment.CurrentRelease.Configuration.MaxInstances)
}

func TestListDeployments(t *testing.T) {
Expand All @@ -1835,11 +1833,9 @@ func TestListDeployments(t *testing.T) {
Name: "Acme, Inc.",
},
Configuration: replicate.DeploymentConfiguration{
Hardware: "gpu-t4",
Scaling: replicate.DeploymentScalingConfiguration{
MinInstances: 1,
MaxInstances: 5,
},
Hardware: "gpu-t4",
MinInstances: 1,
MaxInstances: 5,
},
},
},
Expand All @@ -1857,11 +1853,9 @@ func TestListDeployments(t *testing.T) {
Name: "Acme, Inc.",
},
Configuration: replicate.DeploymentConfiguration{
Hardware: "cpu",
Scaling: replicate.DeploymentScalingConfiguration{
MinInstances: 2,
MaxInstances: 10,
},
Hardware: "cpu",
MinInstances: 2,
MaxInstances: 10,
},
},
},
Expand Down Expand Up @@ -1907,8 +1901,8 @@ func TestListDeployments(t *testing.T) {
assert.Equal(t, "acme", deployments.Results[0].CurrentRelease.CreatedBy.Username)
assert.Equal(t, "Acme, Inc.", deployments.Results[0].CurrentRelease.CreatedBy.Name)
assert.Equal(t, "gpu-t4", deployments.Results[0].CurrentRelease.Configuration.Hardware)
assert.Equal(t, 1, deployments.Results[0].CurrentRelease.Configuration.Scaling.MinInstances)
assert.Equal(t, 5, deployments.Results[0].CurrentRelease.Configuration.Scaling.MaxInstances)
assert.Equal(t, 1, deployments.Results[0].CurrentRelease.Configuration.MinInstances)
assert.Equal(t, 5, deployments.Results[0].CurrentRelease.Configuration.MaxInstances)

// Asserting the second deployment
assert.Equal(t, "acme", deployments.Results[1].Owner)
Expand All @@ -1921,8 +1915,8 @@ func TestListDeployments(t *testing.T) {
assert.Equal(t, "acme", deployments.Results[1].CurrentRelease.CreatedBy.Username)
assert.Equal(t, "Acme, Inc.", deployments.Results[0].CurrentRelease.CreatedBy.Name)
assert.Equal(t, "cpu", deployments.Results[1].CurrentRelease.Configuration.Hardware)
assert.Equal(t, 2, deployments.Results[1].CurrentRelease.Configuration.Scaling.MinInstances)
assert.Equal(t, 10, deployments.Results[1].CurrentRelease.Configuration.Scaling.MaxInstances)
assert.Equal(t, 2, deployments.Results[1].CurrentRelease.Configuration.MinInstances)
assert.Equal(t, 10, deployments.Results[1].CurrentRelease.Configuration.MaxInstances)
}

func TestCreateDeployment(t *testing.T) {
Expand Down Expand Up @@ -1958,11 +1952,9 @@ func TestCreateDeployment(t *testing.T) {
Model: "acme/new-model",
Version: "5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa",
Configuration: replicate.DeploymentConfiguration{
Hardware: "gpu-t4",
Scaling: replicate.DeploymentScalingConfiguration{
MinInstances: 1,
MaxInstances: 5,
},
Hardware: "gpu-t4",
MinInstances: 1,
MaxInstances: 5,
},
CreatedBy: owner,
CreatedAt: timestamp,
Expand Down Expand Up @@ -2003,11 +1995,9 @@ func TestCreateDeployment(t *testing.T) {
Model: options.Model,
Version: options.Version,
Configuration: replicate.DeploymentConfiguration{
Hardware: options.Hardware,
Scaling: replicate.DeploymentScalingConfiguration{
MinInstances: options.MinInstances,
MaxInstances: options.MaxInstances,
},
Hardware: options.Hardware,
MinInstances: options.MinInstances,
MaxInstances: options.MaxInstances,
},
CreatedBy: owner,
CreatedAt: timestamp,
Expand Down Expand Up @@ -2045,8 +2035,8 @@ func TestCreateDeployment(t *testing.T) {
assert.Equal(t, tc.want.CurrentRelease.Model, deployment.CurrentRelease.Model)
assert.Equal(t, tc.want.CurrentRelease.Version, deployment.CurrentRelease.Version)
assert.Equal(t, tc.want.CurrentRelease.Configuration.Hardware, deployment.CurrentRelease.Configuration.Hardware)
assert.Equal(t, tc.want.CurrentRelease.Configuration.Scaling.MinInstances, deployment.CurrentRelease.Configuration.Scaling.MinInstances)
assert.Equal(t, tc.want.CurrentRelease.Configuration.Scaling.MaxInstances, deployment.CurrentRelease.Configuration.Scaling.MaxInstances)
assert.Equal(t, tc.want.CurrentRelease.Configuration.MinInstances, deployment.CurrentRelease.Configuration.MinInstances)
assert.Equal(t, tc.want.CurrentRelease.Configuration.MaxInstances, deployment.CurrentRelease.Configuration.MaxInstances)
assert.Equal(t, tc.want.CurrentRelease.CreatedBy.Name, deployment.CurrentRelease.CreatedBy.Name)
assert.Equal(t, tc.want.CurrentRelease.CreatedAt, deployment.CurrentRelease.CreatedAt)
}
Expand All @@ -2071,11 +2061,9 @@ func TestUpdateDeployment(t *testing.T) {
Model: "acme/original-model",
Version: "5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa",
Configuration: replicate.DeploymentConfiguration{
Hardware: "gpu-t4",
Scaling: replicate.DeploymentScalingConfiguration{
MinInstances: 1,
MaxInstances: 5,
},
Hardware: "gpu-t4",
MinInstances: 1,
MaxInstances: 5,
},
CreatedBy: owner,
CreatedAt: timestamp,
Expand Down Expand Up @@ -2109,11 +2097,9 @@ func TestUpdateDeployment(t *testing.T) {
Model: "acme/updated-model",
Version: "b21cbe271e65c1718f2999b038c18b45e21e4fba961181fbfae9342fc53b9e05",
Configuration: replicate.DeploymentConfiguration{
Hardware: "cpu",
Scaling: replicate.DeploymentScalingConfiguration{
MinInstances: 2,
MaxInstances: 10,
},
Hardware: "cpu",
MinInstances: 2,
MaxInstances: 10,
},
CreatedBy: owner,
CreatedAt: timestamp,
Expand All @@ -2136,11 +2122,9 @@ func TestUpdateDeployment(t *testing.T) {
Model: "acme/original-model",
Version: "5c7d5dc6dd8bf75c1acaa8565735e7986bc5b66206b55cca93cb72c9bf15ccaa",
Configuration: replicate.DeploymentConfiguration{
Hardware: "gpu-t4",
Scaling: replicate.DeploymentScalingConfiguration{
MinInstances: 3,
MaxInstances: 5,
},
Hardware: "gpu-t4",
MinInstances: 3,
MaxInstances: 5,
},
CreatedBy: owner,
CreatedAt: timestamp,
Expand All @@ -2164,11 +2148,9 @@ func TestUpdateDeployment(t *testing.T) {
Model: "acme/model-updated-only",
Version: "b21cbe271e65c1718f2999b038c18b45e21e4fba961181fbfae9342fc53b9e05",
Configuration: replicate.DeploymentConfiguration{
Hardware: "gpu-t4",
Scaling: replicate.DeploymentScalingConfiguration{
MinInstances: 1,
MaxInstances: 5,
},
Hardware: "gpu-t4",
MinInstances: 1,
MaxInstances: 5,
},
CreatedBy: owner,
CreatedAt: timestamp,
Expand Down Expand Up @@ -2223,10 +2205,10 @@ func TestUpdateDeployment(t *testing.T) {
updatedDeployment.CurrentRelease.Configuration.Hardware = *options.Hardware
}
if options.MinInstances != nil {
updatedDeployment.CurrentRelease.Configuration.Scaling.MinInstances = *options.MinInstances
updatedDeployment.CurrentRelease.Configuration.MinInstances = *options.MinInstances
}
if options.MaxInstances != nil {
updatedDeployment.CurrentRelease.Configuration.Scaling.MaxInstances = *options.MaxInstances
updatedDeployment.CurrentRelease.Configuration.MaxInstances = *options.MaxInstances
}

w.WriteHeader(http.StatusOK)
Expand Down Expand Up @@ -2258,8 +2240,8 @@ func TestUpdateDeployment(t *testing.T) {
assert.Equal(t, tc.want.CurrentRelease.Model, deployment.CurrentRelease.Model)
assert.Equal(t, tc.want.CurrentRelease.Version, deployment.CurrentRelease.Version)
assert.Equal(t, tc.want.CurrentRelease.Configuration.Hardware, deployment.CurrentRelease.Configuration.Hardware)
assert.Equal(t, tc.want.CurrentRelease.Configuration.Scaling.MinInstances, deployment.CurrentRelease.Configuration.Scaling.MinInstances)
assert.Equal(t, tc.want.CurrentRelease.Configuration.Scaling.MaxInstances, deployment.CurrentRelease.Configuration.Scaling.MaxInstances)
assert.Equal(t, tc.want.CurrentRelease.Configuration.MinInstances, deployment.CurrentRelease.Configuration.MinInstances)
assert.Equal(t, tc.want.CurrentRelease.Configuration.MaxInstances, deployment.CurrentRelease.Configuration.MaxInstances)
assert.Equal(t, tc.want.CurrentRelease.CreatedBy.Name, deployment.CurrentRelease.CreatedBy.Name)
assert.Equal(t, tc.want.CurrentRelease.CreatedAt, deployment.CurrentRelease.CreatedAt)
}
Expand Down
10 changes: 3 additions & 7 deletions deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,9 @@ type DeploymentRelease struct {
}

type DeploymentConfiguration struct {
Hardware string `json:"hardware"`
Scaling DeploymentScalingConfiguration `json:"scaling"`
}

type DeploymentScalingConfiguration struct {
MinInstances int `json:"min_instances"`
MaxInstances int `json:"max_instances"`
Hardware string `json:"hardware"`
MinInstances int `json:"min_instances"`
MaxInstances int `json:"max_instances"`
}

func (d *Deployment) RawJSON() json.RawMessage {
Expand Down

0 comments on commit cfb9bda

Please sign in to comment.