github.com/ilhicas/nomad@v0.11.8/drivers/docker/progress_test.go (about) 1 package docker 2 3 import ( 4 "testing" 5 "time" 6 7 "github.com/stretchr/testify/require" 8 ) 9 10 func Test_DockerImageProgressManager(t *testing.T) { 11 12 pm := &imageProgressManager{ 13 imageProgress: &imageProgress{ 14 timestamp: time.Now(), 15 layers: make(map[string]*layerProgress), 16 }, 17 } 18 19 _, err := pm.Write([]byte(`{"status":"Pulling from library/golang","id":"1.9.5"} 20 {"status":"Pulling fs layer","progressDetail":{},"id":"c73ab1c6897b"} 21 {"status":"Pulling fs layer","progressDetail":{},"id":"1ab373b3deae"} 22 `)) 23 require.NoError(t, err) 24 require.Equal(t, 2, len(pm.imageProgress.layers), "number of layers should be 2") 25 26 cur := pm.imageProgress.currentBytes() 27 require.Zero(t, cur) 28 tot := pm.imageProgress.totalBytes() 29 require.Zero(t, tot) 30 31 _, err = pm.Write([]byte(`{"status":"Pulling fs layer","progress`)) 32 require.NoError(t, err) 33 require.Equal(t, 2, len(pm.imageProgress.layers), "number of layers should be 2") 34 35 _, err = pm.Write([]byte(`Detail":{},"id":"b542772b4177"}` + "\n")) 36 require.NoError(t, err) 37 require.Equal(t, 3, len(pm.imageProgress.layers), "number of layers should be 3") 38 39 _, err = pm.Write([]byte(`{"status":"Downloading","progressDetail":{"current":45800,"total":4335495},"progress":"[\u003e ] 45.8kB/4.335MB","id":"b542772b4177"} 40 {"status":"Downloading","progressDetail":{"current":113576,"total":11108010},"progress":"[\u003e ] 113.6kB/11.11MB","id":"1ab373b3deae"} 41 {"status":"Downloading","progressDetail":{"current":694257,"total":4335495},"progress":"[========\u003e ] 694.3kB/4.335MB","id":"b542772b4177"}` + "\n")) 42 require.NoError(t, err) 43 require.Equal(t, 3, len(pm.imageProgress.layers), "number of layers should be 3") 44 require.Equal(t, int64(807833), pm.imageProgress.currentBytes()) 45 require.Equal(t, int64(15443505), pm.imageProgress.totalBytes()) 46 47 _, err = pm.Write([]byte(`{"status":"Download complete","progressDetail":{},"id":"b542772b4177"}` + "\n")) 48 require.NoError(t, err) 49 require.Equal(t, 3, len(pm.imageProgress.layers), "number of layers should be 3") 50 require.Equal(t, int64(4449071), pm.imageProgress.currentBytes()) 51 require.Equal(t, int64(15443505), pm.imageProgress.totalBytes()) 52 }