github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/worker/uniter/storage/export_test.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package storage
     5  
     6  import (
     7  	"github.com/juju/names"
     8  
     9  	"github.com/juju/juju/apiserver/params"
    10  	"github.com/juju/juju/worker/uniter/hook"
    11  	"github.com/juju/juju/worker/uniter/runner/jujuc"
    12  )
    13  
    14  type State interface {
    15  	hook.Committer
    16  	hook.Validator
    17  }
    18  
    19  type StorageHookQueue interface {
    20  	Empty() bool
    21  	Next() hook.Info
    22  	Pop()
    23  	Update(attachment params.StorageAttachment) error
    24  	Context() (jujuc.ContextStorageAttachment, bool)
    25  }
    26  
    27  func StateAttached(s State) bool {
    28  	return s.(*stateFile).attached
    29  }
    30  
    31  func ValidateHook(tag names.StorageTag, attached bool, hi hook.Info) error {
    32  	st := &state{tag, attached}
    33  	return st.ValidateHook(hi)
    34  }
    35  
    36  func ReadStateFile(dirPath string, tag names.StorageTag) (d State, err error) {
    37  	state, err := readStateFile(dirPath, tag)
    38  	return state, err
    39  }
    40  
    41  func ReadAllStateFiles(dirPath string) (map[names.StorageTag]State, error) {
    42  	files, err := readAllStateFiles(dirPath)
    43  	if err != nil {
    44  		return nil, err
    45  	}
    46  	states := make(map[names.StorageTag]State)
    47  	for tag, f := range files {
    48  		states[tag] = f
    49  	}
    50  	return states, nil
    51  }
    52  
    53  func NewStorageHookQueue(
    54  	unitTag names.UnitTag,
    55  	storageTag names.StorageTag,
    56  	attached bool,
    57  ) StorageHookQueue {
    58  	return &storageHookQueue{
    59  		unitTag:    unitTag,
    60  		storageTag: storageTag,
    61  		attached:   attached,
    62  	}
    63  }
    64  
    65  func NewStorageSource(
    66  	st StorageAccessor,
    67  	unitTag names.UnitTag,
    68  	storageTag names.StorageTag,
    69  	attached bool,
    70  ) (hook.Source, error) {
    71  	source, err := newStorageSource(st, unitTag, storageTag, attached)
    72  	return source, err
    73  }