github.com/tych0/umoci@v0.4.2/api_test.go (about)

     1  /*
     2   * umoci: Umoci Modifies Open Containers' Images
     3   * Copyright (C) 2018 Cisco Systems
     4   *
     5   * Licensed under the Apache License, Version 2.0 (the "License");
     6   * you may not use this file except in compliance with the License.
     7   * You may obtain a copy of the License at
     8   *
     9   *    http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   */
    17  
    18  package umoci
    19  
    20  import (
    21  	"io/ioutil"
    22  	"os"
    23  	"testing"
    24  )
    25  
    26  func TestCreateExistingFails(t *testing.T) {
    27  	dir, err := ioutil.TempDir("", "umoci_testCreateExistingFails")
    28  	if err != nil {
    29  		t.Fatal(err)
    30  	}
    31  	defer os.RemoveAll(dir)
    32  
    33  	// opening a bad layout should fail
    34  	_, err = OpenLayout(dir)
    35  	if err == nil {
    36  		t.Fatal("opening non-existent layout succeeded?")
    37  	}
    38  
    39  	// remove directory so that create can create it
    40  	os.RemoveAll(dir)
    41  
    42  	// create should work
    43  	_, err = CreateLayout(dir)
    44  	if err != nil {
    45  		t.Fatal(err)
    46  	}
    47  
    48  	// but not twice
    49  	_, err = CreateLayout(dir)
    50  	if err == nil {
    51  		t.Fatal("create worked twice?")
    52  	}
    53  
    54  	// but open should work now
    55  	_, err = OpenLayout(dir)
    56  	if err != nil {
    57  		t.Fatal(err)
    58  	}
    59  }