ubclaunchpad / inertia

✈️ Effortless, self-hosted continuous deployment for small teams and projects
https://inertia.ubclaunchpad.com
MIT License
153 stars 18 forks source link

daemon: fix version update checks #717

Closed chuck-sys closed 3 years ago

chuck-sys commented 4 years ago

:tickets: Ticket(s): Closes #716


:construction_worker: Changes

Check that the current version of inertiad is actually not the latest version before saying that a new version is available.

:flashlight: Testing Instructions

Not sure about that one. Will need help.

codecov[bot] commented 4 years ago

Codecov Report

Merging #717 (449ddd0) into master (690a5eb) will decrease coverage by 0.06%. The diff coverage is 69.70%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #717      +/-   ##
==========================================
- Coverage   49.43%   49.37%   -0.05%     
==========================================
  Files          75       75              
  Lines        3561     3557       -4     
==========================================
- Hits         1760     1756       -4     
+ Misses       1546     1544       -2     
- Partials      255      257       +2     
Flag Coverage Δ
test-bootstrap-amazon-1 1.24% <0.00%> (+0.01%) :arrow_up:
test-bootstrap-centos-7 1.24% <0.00%> (+0.01%) :arrow_up:
test-bootstrap-debian-9.3 1.24% <0.00%> (+0.01%) :arrow_up:
test-bootstrap-pull-image 1.24% <0.00%> (+0.01%) :arrow_up:
test-bootstrap-ubuntu-16.04 1.24% <0.00%> (+0.01%) :arrow_up:
test-bootstrap-ubuntu-18.04 1.24% <0.00%> (+0.01%) :arrow_up:
test-core 48.98% <69.70%> (-0.05%) :arrow_down:
test-windows 41.31% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
api/response.go 88.89% <ø> (ø)
cmd/core/utils/out/format.go 85.72% <ø> (ø)
daemon/inertiad/build/builder.go 74.31% <ø> (ø)
daemon/inertiad/notify/notifier.go 37.50% <ø> (ø)
daemon/inertiad/project/deployment.go 33.34% <ø> (ø)
daemon/inertiad/daemon/status.go 72.10% <68.75%> (-2.37%) :arrow_down:
client/client.go 73.37% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 690a5eb...449ddd0. Read the comment docs.

chuck-sys commented 4 years ago

Awesome, thanks! Do you think you could try and include a case for this in the tests? sourcegraph.com/github.com/ubclaunchpad/inertia/-/blob/daemon/inertiad/daemon/status_test.go#L64 (not necessary I suppose but would be nice :) )

I'll try

chuck-sys commented 4 years ago

@bobheadxi Need some help. Not sure why the Deployment status doesn't update even after putting it into another variable. Is it copying it?

func TestStatusHandlerNotUpToDate(t *testing.T) {
    status := api.DeploymentStatus{
        Branch:               "wow",
        CommitHash:           "abcde",
        CommitMessage:        "",
        Containers:           []string{},
        BuildContainerActive: false,
    }

    var s = &Server{
        deployment: &mocks.FakeDeployer{
            GetStatusStub: func(*docker.Client) (api.DeploymentStatus, error) {
                return status, nil
            },
        },
        version: "v1.0.0",
    }

    // Assemble request
    req, err := http.NewRequest("GET", "/status", nil)
    assert.NoError(t, err)

    // Record responses
    recorder := httptest.NewRecorder()
    handler := http.HandlerFunc(s.statusHandler)

    handler.ServeHTTP(recorder, req)
    assert.Equal(t, recorder.Code, http.StatusOK)

    // Check status
    assert.Equal(t, status.InertiaVersion, s.version)           // sanity checking, which doesn't work
    assert.NotNil(t, status.NewVersionAvailable)
    assert.NotEqual(t, status.NewVersionAvailable, s.version)
}
bobheadxi commented 4 years ago

@cheukyin699 the GetStatusStub mocks the deployment's status function, you will need to include the version in status :)

    status := api.DeploymentStatus{
        Branch:               "wow",
        CommitHash:           "abcde",
        CommitMessage:        "",
        Containers:           []string{},
        BuildContainerActive: false,
+       InertiaVersion:       "v1.0.0",
    }

https://sourcegraph.com/github.com/ubclaunchpad/inertia/-/blob/api/response.go#L92