gitee.com/mysnapcore/mysnapd@v0.1.0/cmd/snap/cmd_ensure_state_soon_test.go (about)

     1  // -*- Mode: Go; indent-tabs-mode: t -*-
     2  
     3  /*
     4   * Copyright (C) 2017 Canonical Ltd
     5   *
     6   * This program is free software: you can redistribute it and/or modify
     7   * it under the terms of the GNU General Public License version 3 as
     8   * published by the Free Software Foundation.
     9   *
    10   * This program is distributed in the hope that it will be useful,
    11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13   * GNU General Public License for more details.
    14   *
    15   * You should have received a copy of the GNU General Public License
    16   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17   *
    18   */
    19  
    20  package main_test
    21  
    22  import (
    23  	"fmt"
    24  	"io/ioutil"
    25  	"net/http"
    26  
    27  	"gopkg.in/check.v1"
    28  
    29  	snap "gitee.com/mysnapcore/mysnapd/cmd/snap"
    30  )
    31  
    32  func (s *SnapSuite) TestEnsureStateSoon(c *check.C) {
    33  	n := 0
    34  	s.RedirectClientToTestServer(func(w http.ResponseWriter, r *http.Request) {
    35  		switch n {
    36  		case 0:
    37  			c.Check(r.Method, check.Equals, "POST")
    38  			c.Check(r.URL.Path, check.Equals, "/v2/debug")
    39  			c.Check(r.URL.RawQuery, check.Equals, "")
    40  			data, err := ioutil.ReadAll(r.Body)
    41  			c.Check(err, check.IsNil)
    42  			c.Check(data, check.DeepEquals, []byte(`{"action":"ensure-state-soon"}`))
    43  			fmt.Fprintln(w, `{"type": "sync", "result": true}`)
    44  		default:
    45  			c.Fatalf("expected to get 1 requests, now on %d", n+1)
    46  		}
    47  
    48  		n++
    49  	})
    50  	rest, err := snap.Parser(snap.Client()).ParseArgs([]string{"debug", "ensure-state-soon"})
    51  	c.Assert(err, check.IsNil)
    52  	c.Assert(rest, check.DeepEquals, []string{})
    53  	c.Check(s.Stdout(), check.Equals, "")
    54  	c.Check(s.Stderr(), check.Equals, "")
    55  }